package com.yanqu.road.server.cmd.activity.rankunionwar;

import com.yanqu.road.entity.enums.eChatContentType;
import com.yanqu.road.entity.enums.eMessageType;
import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.RankUnionWarProto;
import com.yanqu.road.pb.worldmessage.WorldMessageProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.player.WorldMessageMgr;
import com.yanqu.road.server.manager.union.CrossUnionReqContext;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.utils.date.DateHelper;

@Cmd(code = CrossProtocol.C3_CROSS_RANKUNIONWAR_APPOINT_COMMANDER, desc = "")
public class Cross3RankUnionWarAppointCommanderReqCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        RankUnionWarProto.CrossRankUnionWarAppointCommanderReqMsg reqMsg = RankUnionWarProto.CrossRankUnionWarAppointCommanderReqMsg.parseFrom(packet.getBytes());
        CrossUnionReqContext context = CrossUnionReqContext.initContext(serverId, reqMsg.getUserId()).loadUnionMember().loadUnionInfo();
        if(context.getRet() == 0){
            for(long appointCommanderUserId : reqMsg.getCommanderUserIdList()){
                UserBaseInfo userBaseInfo = CrossUserMgr.getUserBaseInfo(appointCommanderUserId);
                if(userBaseInfo != null){
                    //商会频道消息
                    String content = WorldMessageMgr.encodeContent(context.getUserBaseInfo().getUserBaseInfo().getNickName(),userBaseInfo.getNickName() , reqMsg.getLine());
                    WorldMessageProto.WorldMessageTempMsg.Builder chatMsg = WorldMessageMgr.parseWorldMessageTempMsg(context.getUserBaseInfo(),
                            eMessageType.RankUnionWarAppointCommander.getValue(), eChatContentType.Common.getContentType(), content, DateHelper.getCurrentTime(), 0, null);
                    WorldMessageMgr.sendUnionChat(context.getMember().getServerId(), context.getPlayerId(), chatMsg, context.getUnionInfo().getUnionUid());
                }
            }

        }
    }

    @Override
    public void sendData() {

    }
}
